package com.example.controller;

import com.example.common.Result;
import com.example.entity.RegistrationForm;
import com.example.service.RegistrationFormService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 挂号单前端操作接口
 **/
@RestController
@RequestMapping("/RegistrationForm")
public class RegistrationFormController {

    @Resource
    private RegistrationFormService registrationFormService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody RegistrationForm RegistrationForm) {
        registrationFormService.add(RegistrationForm);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        registrationFormService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        registrationFormService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody RegistrationForm RegistrationForm) {
        registrationFormService.updateById(RegistrationForm);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        RegistrationForm RegistrationForm = registrationFormService.selectById(id);
        return Result.success(RegistrationForm);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(RegistrationForm RegistrationForm) {
        List<RegistrationForm> list = registrationFormService.selectAll(RegistrationForm);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(RegistrationForm RegistrationForm,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<RegistrationForm> page = registrationFormService.selectPage(RegistrationForm, pageNum, pageSize);
        return Result.success(page);
    }

    @GetMapping("/selectPageInDoctor")
    public Result selectPageInDoctor(RegistrationForm registrationForm,
                                     @RequestParam(defaultValue = "1") Integer pageNum,
                                     @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<RegistrationForm> page = registrationFormService.selectPageInDoctor(registrationForm, pageNum, pageSize);
        return Result.success(page);
    }

}